using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using DataAccess;
using DataTransferObject;

namespace Business
{
    public enum TheLoaiBUSResult
    {
        OK,
        MATLERROR,
        TENTLERROR,
        DAOERROR
    }

    public class clsTheLoaiBUS
    {
        //Fields.
        private clsTheLoaiDAO TheLoaiDAO;

        //Constructors.
        public clsTheLoaiBUS()
        {
            this.TheLoaiDAO = new clsTheLoaiDAO();
        }

        #region Methods

        public TheLoaiBUSResult KiemTraRong(clsTheLoaiDTO obj)
        {
            if (obj.MaTL == "")
                return TheLoaiBUSResult.MATLERROR;
            if (obj.TenTL == "")
                return TheLoaiBUSResult.TENTLERROR;
            return TheLoaiBUSResult.OK;
        }

        public DataTable DanhSachTheLoai()
        {
            return this.TheLoaiDAO.SelectAll();
        }

        public DataTable ThongKeTheLoai(clsTheLoaiDTO obj)
        {
            return this.TheLoaiDAO.ThongKeTheoTheLoai(obj);
        }

        public TheLoaiBUSResult ThemTheLoai(clsTheLoaiDTO obj)
        {
            if (!this.TheLoaiDAO.Insert(obj))
                return TheLoaiBUSResult.DAOERROR;
            return TheLoaiBUSResult.OK;
        }

        public TheLoaiBUSResult SuaTheLoai(clsTheLoaiDTO obj)
        {
            if (!this.TheLoaiDAO.Update(obj))
                return TheLoaiBUSResult.DAOERROR;
            return TheLoaiBUSResult.OK;
        }

        public TheLoaiBUSResult XoaTheLoai(clsTheLoaiDTO obj)
        {
            if (!this.TheLoaiDAO.Delete(obj))
                return TheLoaiBUSResult.DAOERROR;
            return TheLoaiBUSResult.OK;
        }
        #endregion
    }
}
